<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise async await</title>
</head>

<body>
    <script>
        // 创建一个promise实例    resolve和reject，分别表示异步执行成功后的回调函数和异步执行失败后的回调函数；
        // promise 相当于承诺  resolve和reject  表示执行成功和执行失败的状态   里面的函数代表执行结果， 根据结果返回给resolve和reject
        const promise = new Promise((resolve, reject) => {
            console.log('执行成功结果')
            // 控制执行成功与失败
            setTimeout(() => {
                let i = 0
                if (i) {
                    resolve(i)
                } else {
                    reject(i)
                }
            }, 5000);
        })

        promise.then(data => {
            console.log(data)
        }).catch(err => {
            console.log(err)
        })
    </script>
</body>

</html>